var path  = 'https://xhhfe.xinhehui.com/index/';
var toppath = 'https://xhhfe.xinhehui.com/';
var app = getApp()
var api = {
    //获取项目列表
    getactiveList:function(id,cb){
        return wx.request({
            url: toppath+ 'product/index?id='+id,
            header: {
                'content-type': 'application/json'
            },
            success: function(res) {
                var list = res.data.data
                typeof cb == "function" && cb(list)
            }
        })
    },
    //获取用户类型
    getuserinfo:function(openid,cb){
       return wx.request({
            url: path+ 'getuserinfo',
            header: {
                'content-type': 'application/json'
            },
            data:{
                openid:openid
            },
            success: function(res) {
                var data =  res.data
                typeof cb == "function" && cb(data)
            },
            fail: function(res) {
                cb({cannotFetch:true})
            }
        }) 
    },
    //获取项目经理列表，技术经理列表
    getuserlist:function(cb){
        return wx.request({
            url: path+ 'getteamleaders', 
            header: {
                'content-type': 'application/json'
            },
            success: function(res) {
                var data =  res.data.data
                typeof cb == "function" && cb(data)
            }
        })
    },
    //创建项目
    createproduct:function(data,cb){
        return wx.request({
            url: path+ 'createproduct', 
            header: {
                'content-type': 'application/json'
            },
            method:"POST",
            data:data,
            success: function(res) {
                var data =  res.data
                typeof cb == "function" && cb(data)
            }
        })
    },
    //获取指定项目的信息
    getProductInfo:function(pid,cb){
        return wx.request({
            url: toppath+ 'product/getinfo',
            header: {
                'content-type': 'application/json'
            },
            data:{pid:pid},
            success: function(res) {
                var list = res.data.data
                typeof cb == "function" && cb(list)
            }
        })
    },
    //获取指定项目的信息+组别
    getProductInfoWithTeamlist:function(pid,cb){
        return wx.request({
            url: toppath+ 'product/getinfowithteamlist',
            header: {
                'content-type': 'application/json'
            },
            data:{pid:pid},
            success: function(res) {
                var list = res.data.data
                typeof cb == "function" && cb(list)
            }
        })
    },
    //更改项目状态
    setProductInfo:function(pid,data,cb){
        return wx.request({
            url: path+ 'setproductInfo',
            header: {
                'content-type': 'application/json'
            },
            method:"POST",
            data:{pid:pid,data:data},
            success: function(res) {
                var list = res.data
                typeof cb == "function" && cb(list)
            }
        })
    },
    //打分
    score:function(data,cb){
        return wx.request({
            url: path+ 'score',
            header: {
                'content-type': 'application/json'
            },
            method:"POST",
            data:data,
            success: function(res) {
                var list = res.data
                typeof cb == "function" && cb(list)
            }
        })
    },
    joinproduct:function(pid,uid,data,cb){
        return wx.request({
            url: path+ 'joinproduct',
            header: {
                'content-type': 'application/json'
            },
            method:"POST",
            data:{pid:pid,uid:uid,data:data},
            success: function(res) {
                var list = res.data
                typeof cb == "function" && cb(list)
            }
        })
    },
    //项目经理打分列出组长的名单，组长打分，列出组员的名单
    getscoreat:function(uid,pid,cb){
        return wx.request({
            url: path+ 'getscoreat',
            header: {
                'content-type': 'application/json'
            },
            data:{pid:pid,uid:uid},
            success: function(res) {
                var list = res.data
                typeof cb == "function" && cb(list)
            }
        })
    },
    //获取用户参加过的所有项目
    getuserproductlist:function(uid,cb){
        return wx.request({
            url: toppath+ 'product_user/index',
            header: {
                'content-type': 'application/json'
            },
            data:{uid:uid},
            success: function(res) {
                var list = res.data
                typeof cb == "function" && cb(list)
            }
        })
    },
    //获取二维码
    getqrcode:function(pid,cb){
         return wx.request({
            url: toppath+ 'product/getqrcode',
            header: {
                'content-type': 'application/json'
            },
            data:{pid:pid},
            success: function(res) {
                var list = res.data.data
                typeof cb == "function" && cb(list)
            }
        })
    }

}
module.exports.api = api